﻿using iMES.Core.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System;
using YUN.ProductionManage.IServices;
using Microsoft.AspNetCore.Authorization;
using iMES.Entity.DomainModels;

namespace iMES.WebApi.Cloudsian
{
    public partial class ProductionPlanningController 
    {
        private readonly IProduct_ProductPlanningService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public ProductionPlanningController(
            IProduct_ProductPlanningService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// 获取订单明细
        /// </summary>
        /// <returns></returns>
        ///[ApiActionPermission(Enums.ActionPermissionOptions.Delete)] 必须有删除权限才能调用该方法
        [Route("cancelPlans"), HttpPost]
        [AllowAnonymous]
        public ActionResult CancelPlans([FromBody] List<Guid> planIds)
        {
            var result = Service.CancelPlans(planIds);
            return Json(result);
        }
        /// <summary>
        /// 批量添加工时和机台
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [Route("batchAddWorkingHoursAndMachineTools"), HttpPost]
        [AllowAnonymous] // 可选，根据权限需求设置
        public ActionResult BatchAddWorkingHoursAndMachineTools([FromBody] BatchAddScheduleDto dto)
        {
            var result = _service.BatchAddWorkingHoursAndMachineTools(
                dto.ProductionPlanningId,
                dto.WorkingHoursList,
                dto.MachineToolList,
                dto.PlanningStartDate,
                dto.PlanningEndDate
            );
            return Json(result);
        }
    }
    public class BatchAddScheduleDto
    {
        public Guid ProductionPlanningId { get; set; }
        public List<WorkingHours> WorkingHoursList { get; set; }
        public List<MachineTool> MachineToolList { get; set; }
        public DateTime? PlanningStartDate { get; set; }
        public DateTime? PlanningEndDate { get; set; }
    }
}
